﻿@model ThaireInvestmentWeb.Models.EditEquitySaleModel
@{
    ViewBag.Title = "Edit Equity Sale";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {

        $("#TradeDate,#SettlementDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")'
            });

        $("#CancelBtn").click(function (event) {
            //showConfirm("Are you sure to cancel ?", CancelBtnAction);
            showConfirm(null, CancelBtnAction);
            return false;
        });
        $("#Unit").change(calAll);
        $("#PriceUnit").change(calAll);
        $("#ParUnit").change(calAll);
        $("#ComRate").change(calAll);
        $("#VatRate").change(calAll);
        $("#WHTaxRate").change(calAll);
    });
    
    function CancelBtnAction(event) {
        window.location.href = 'EditEquityHeader?headerId=@Model.HeaderID';
    }

    function calAll() {
        calGrossAmount();
        calParAmount();
        calComAmount();
        calVatAmount();
        calPurchaseValueNet();
        calWHTaxAmount();
        calNetSettle();
    }
    function calPurchaseValueNet() {
        var v1 = $("#Transaction_ComAmount").val();
        var v2 = $("#Transaction_GrossAmount").val();
        var v3 = $("#Transaction_VatAmount").val();
        if (v1 != '' && v2 != '' && v3 != '') {
            var total = parseFloat(v1) + parseFloat(v2) + parseFloat(v3);
            $('#Transaction_PurchaseValueNet').val(total);
        }
    }
    function calNetSettle() {
        var v1 = $("#Transaction_PurchaseValueNet").val();
        var v2 = $("#Transaction_WHTaxAmount").val();
        if (v1 != '' && v2 != '') {
            var total = v1 - v2;
            $('#Transaction_NetSettle').val(total);
        }
    }
    function calGrossAmount () {
        var v1 = $("#Unit").val();
        var v2 = $("#PriceUnit").val();
        if (v1 != '' && v2 != '') {
            var total = v1 * v2;
            $('#Transaction_GrossAmount').val(total);
        }
    }
    function calParAmount() {
        var v1 = $("#Unit").val();
        var v2 = $("#ParUnit").val();
        if (v1 != '' && v2 != '') {
            var total = v1 * v2;
            $('#Transaction_ParAmount').val(total);
        }
    }
    function calComAmount() {
        var v1 = $("#ComRate").val();
        var v2 = $("#Transaction_GrossAmount").val();
        if (v1 != '' && v2 != '') {
            var total = v1 * v2 /100;
            $('#Transaction_ComAmount').val(total);
        }
    }
    function calVatAmount() {
        var v1 = $("#VatRate").val();
        var v2 = $("#Transaction_GrossAmount").val();
        if (v1 != '' && v2 != '') {
            var total = v1 * v2 / 100;
            $('#Transaction_VatAmount').val(total);
        }
    }

    function calWHTaxAmount() {
        var v1 = $("#WHTaxRate").val();
        var v2 = $("#Transaction_ComAmount").val();
        if (v1 != '' && v2 != '') {
            var total = v1 * v2 / 100;
            $('#Transaction_WHTaxAmount').val(total);
        }
    }

</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > <a href="@Url.Action("ManageEquity", "Equity", new { headerId = Model.Header.EquityHeaderID })">Equity Securities</a> > <a href="@Url.Action("EditEquityHeader", "Equity", new { headerId = Model.Header.EquityHeaderID })">Header</a> > Sale
            </div>
        </td>
    </tr>
</table>
<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">INPUT 
            Sale Equity Securities - Listed</td>
    </tr>
</table>

<table width="100%" border="0" align="center">
    <tr>
        <td>
            @Html.Partial("_EquityHeaderView", Model.HeaderDTO)
            @Html.ValidationSummary(true)
            @using (Html.BeginForm("EditSaleTransaction", "Equity", FormMethod.Post, new { id = "mainForm" }))
            {
                <table style="margin-top: 20px;" class="tableform" width="100%" border="5" align="center" cellspacing="2">
                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Transaction Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedTransactionType, Model.TransactionTypeList)
                            @Html.ValidationMessageFor(model => model.SelectedTransactionType)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Ref. No.<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.RefNo)
                            @Html.ValidationMessageFor(model => model.RefNo)</td>
                        <td>
                            <div align="right">Type of Payment<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedTypeOfPayment, Model.TypeOfPaymentList)
                            @Html.ValidationMessageFor(model => model.SelectedTypeOfPayment)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Trade Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.TradeDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.TradeDate) })
                            @Html.ValidationMessageFor(model => model.TradeDate)</td>
                        <td>
                            <div align="right">Settlement Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.SettlementDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.SettlementDate) })
                            @Html.ValidationMessageFor(model => model.SettlementDate)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Unit<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.Unit)
                            @Html.ValidationMessageFor(model => model.Unit)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Par / Unit<span class="error"> * </span>:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.ParUnit)
                            @Html.ValidationMessageFor(model => model.ParUnit)</td>
                        <td>
                            <div align="right">Par<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.ParAmount, new { @readonly = "readonly", @class = "inputNumberField" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Price / Unit<span class="error"> * </span>:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.PriceUnit)
                            @Html.ValidationMessageFor(model => model.PriceUnit)</td>
                        <td>
                            <div align="right">Gross Amount<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.GrossAmount, new { @readonly = "readonly", @class = "inputNumberField" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">COM<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.ComRate)
                            @Html.ValidationMessageFor(model => model.ComRate) (%)</td>
                        <td>
                            <div align="right">COM AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.ComAmount, new { @readonly = "readonly", @class = "inputNumberField" })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">VAT Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.VatRate) @Html.ValidationMessageFor(model => model.VatRate) (%)</td>
                        <td>
                            <div align="right">VAT AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.VatAmount, new { @readonly = "readonly", @class = "inputNumberField" })</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Purchase Value (Net)<span class="error"></span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Transaction.PurchaseValueNet, new { @readonly = "readonly", @class = "inputNumberField" })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">W/H TAX Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.WHTaxRate) @Html.ValidationMessageFor(model => model.WHTaxRate)
                            &nbsp;(%)</td>
                        <td>
                            <div align="right">W/H TAX AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.WHTaxAmount, new { @readonly = "readonly", @class = "inputNumberField" })
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Net Settle AMT. incl W/T<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Transaction.NetSettle, new { @readonly = "readonly", @class = "inputNumberField" })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Physical<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedPhysical, Model.PhysicalList)  @Html.ValidationMessageFor(model => model.SelectedPhysical)</td>
                        <td>
                            <div align="right">Keep at<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedKeepAt, Model.KeepAtList)  @Html.ValidationMessageFor(model => model.SelectedKeepAt)</td>
                    </tr>
                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                </table>
    
                <table width="95%" height="85" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">

                                <input id="SubmitBtn" type="submit" name="SubmitBtn" value=" Submit " class="button" need-confirm="true"/>
                                &nbsp;&nbsp; 
                            <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button" />
                            </div>
                        </td>
                    </tr>

                </table>
    
                @Html.HiddenFor(x => x.UpdateMode);
                @Html.HiddenFor(x => x.HeaderID);
                @Html.HiddenFor(x => x.TransactionID);

            }

        </td>
    </tr>
</table>
